class editBox extends squareObject{
  String typedText = "";
  
  PFont font;
  int lev=1;
  
  boolean focus = false;
  
  boolean state, pstate;
  
  editBox(String id, float x, float y){
    super(id, x, y, 50, 20);
    font = createFont("Helvetica", 18);
  }

  editBox(String id, float x, float y, float w, float h){
    super(id, x, y, w, h);
    font = createFont("Helvetica", 18);
//    w = 100;
//    h = lev*40;

  }

  void display(){
    pushStyle();
    fill(255,255,255);
    stroke(0);
    rect(x, y, w, h);
    fill(0,0,0);
    if (font != null) textFont(font);
    float posX = (g.rectMode == RADIUS || g.rectMode == CENTER) ? x - w : x + x/6;
    if (focus) text(typedText+(frameCount/10 % 2 == 0 ? "_" : ""), posX, y +h/2);
    else text(typedText, posX, y +h/2);
    state = keyPressed;
    if (state && !pstate && focus){
      update();
      pstate = state;
    }
    if (!state) pstate = state;
    popStyle();
  }
 
  void update(){
    if (key != CODED) {
      switch(key) {
      case BACKSPACE:
        typedText = typedText.substring(0,max(0,typedText.length()-1));
        break;
      case TAB:
        typedText += "    ";
        break;
      case ENTER:
      case RETURN:
        break;
      case ESC:
      case DELETE:
        break;
      default:
        typedText += key;
      }
    }
  }
  
  String getText(){
    return typedText;
  }
  
  void setFocus(boolean x){ focus = x;}
  
}
